package 尊享面试.数组_字符串;

public class a1055形成字符串的最短路径 {
    static class Solution {
        public int shortestWay(String source, String target) {
            int ans = 0;
            int slen = source.length();
            int tlen = target.length();
            int j = 0;
            while (j < tlen) {
                int i = 0;
                int start = j;
                while (i < slen && j < tlen) {
                    if (source.charAt(i) == target.charAt(j)) {
                        j++;
                    }
                    i++;
                }
                if (start == j) {
                    return -1;
                }
                ans++;
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String source = "xyz", target = "xzyxz";
        System.out.println(solution.shortestWay(source, target));
    }
}
